﻿namespace SBValidation
{
    /// <summary>
    /// Provides entry class for validation.
    /// </summary>
    /// <typeparam name="T">Type to validate.</typeparam>
    public class Validation<T>
    {
        private bool isValid = true;

        /// <summary>
        /// Initializes a new instance of the <see cref="Validation{T}"/> class.
        /// </summary>
        /// <param name="value">The value to validate.</param>
        public Validation(T value)
        {
            Value = value;
        }

        /// <summary>
        /// Gets or sets the value to validate.
        /// </summary>
        /// <value>The value to validate.</value>
        public T Value 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Gets or sets a value indicating whether value is valid.
        /// </summary>
        /// <value><c>true</c> if value is valid; otherwise, <c>false</c>.</value>
        public bool IsValid
        {
            get
            {
                return isValid;
            }
            set
            {
                isValid &= value;
            }
        }

        /// <summary>
        /// Performs an implicit conversion from <see cref="Validation{T}"/> to <see cref="System.Boolean"/>.
        /// </summary>
        /// <param name="validation">The validation.</param>
        /// <returns>The result of the conversion.</returns>
        public static implicit operator bool(Validation<T> validation)
        {
            return validation.IsValid;
        }
    }
}